﻿package view.popup
{
    import cmd.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import manager.*;
    import morn.core.components.*;

    public class NewSureDialogUI extends View implements IDialogUI
    {
        public var closeBtn:Button;
        public var item_name:Label;
        public var textinput2:Label;
        public var yuanbaoImg:Image;
        public var sureBtn:Button;
        public var cancelBtn:Button;
        public var textinput1:Label;
        public var goldImg:Image;
        protected var uiXML:XML;
        private var item:Loader;
        private var curCount:int = 1;
        private var data:Object;
        private var maxCount:int = 1;
        private var index:int;
        private var rid:int;
        private var price:int;
        private var background:Sprite;

        public function NewSureDialogUI()
        {
            this.uiXML = <View>r
n	t	t	t  <Image url=""png.common.cs2_tsbg"" x=""1"" y=""0"" width=""285"" height=""273"" sizeGrid=""10,50,10,10""/>r
n	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""253"" y=""5"" var=""closeBtn""/>r
n	t	t	t  <Label text=""label"" x=""77"" y=""128"" color=""0xffe4c7"" var=""item_name"" stroke=""1"" font=""SimSun"" width=""142"" height=""18"" align=""center""/>r
n	t	t	t  <Image url=""png.common.s9_itembg"" x=""93"" y=""185"" width=""140"" height=""33"" sizeGrid=""10,10,10,10""/>r
n	t	t	t  <Label x=""124"" y=""193"" width=""106"" color=""0x766b62"" font=""SimSun"" var=""textinput2"" editable=""true"" align=""center""/>r
n	t	t	t  <Image url=""png.common.cs2_yuanbao"" x=""102"" y=""193"" var=""yuanbaoImg""/>r
n	t	t	t  <Button label=""确定"" skin=""png.common.btn_cs2_bag"" x=""44"" y=""224"" labelColors=""0xb29a6c,0xb29a6c,0xfff7af"" labelStroke=""1"" labelFont=""SimSun"" var=""sureBtn""/>r
n	t	t	t  <Button label=""取消"" skin=""png.common.btn_cs2_bag"" x=""172"" y=""224"" labelColors=""0xb29a6c,0xb29a6c,0xfff7af"" labelStroke=""1"" labelFont=""SimSun"" var=""cancelBtn""/>r
n	t	t	t  <Label text=""购买"" x=""125"" y=""4"" font=""Microsoft YaHei"" size=""15"" bold=""true"" color=""0xffeecd""/>r
n	t	t	t  <Image url=""png.common.s9_itembg"" x=""93"" y=""151"" width=""140"" height=""33"" sizeGrid=""10,10,10,10""/>r
n	t	t	t  <Label text=""总价"" x=""59"" y=""192"" color=""0xb9774b"" stroke=""1"" font=""SimSun""/>r
n	t	t	t  <Label text=""数量"" x=""59"" y=""157"" color=""0xb9774b"" stroke=""1"" font=""SimSun""/>r
n	t	t	t  <Label x=""102"" y=""159"" width=""125"" color=""0x766b62"" font=""SimSun"" var=""textinput1"" editable=""true"" align=""center""/>r
n	t	t	t  <Image url=""jpg.common.cs2_bg3"" x=""110"" y=""52""/>r
n	t	t	t  <Image url=""png.common.cs2_jinbi"" x=""103"" y=""193"" var=""goldImg""/>r
n	t	t	t</View>")("<View>
			  <Image url="png.common.cs2_tsbg" x="1" y="0" width="285" height="273" sizeGrid="10,50,10,10"/>
			  <Button skin="png.common.btn_cs2_close" x="253" y="5" var="closeBtn"/>
			  <Label text="label" x="77" y="128" color="0xffe4c7" var="item_name" stroke="1" font="SimSun" width="142" height="18" align="center"/>
			  <Image url="png.common.s9_itembg" x="93" y="185" width="140" height="33" sizeGrid="10,10,10,10"/>
			  <Label x="124" y="193" width="106" color="0x766b62" font="SimSun" var="textinput2" editable="true" align="center"/>
			  <Image url="png.common.cs2_yuanbao" x="102" y="193" var="yuanbaoImg"/>
			  <Button label="确定" skin="png.common.btn_cs2_bag" x="44" y="224" labelColors="0xb29a6c,0xb29a6c,0xfff7af" labelStroke="1" labelFont="SimSun" var="sureBtn"/>
			  <Button label="取消" skin="png.common.btn_cs2_bag" x="172" y="224" labelColors="0xb29a6c,0xb29a6c,0xfff7af" labelStroke="1" labelFont="SimSun" var="cancelBtn"/>
			  <Label text="购买" x="125" y="4" font="Microsoft YaHei" size="15" bold="true" color="0xffeecd"/>
			  <Image url="png.common.s9_itembg" x="93" y="151" width="140" height="33" sizeGrid="10,10,10,10"/>
			  <Label text="总价" x="59" y="192" color="0xb9774b" stroke="1" font="SimSun"/>
			  <Label text="数量" x="59" y="157" color="0xb9774b" stroke="1" font="SimSun"/>
			  <Label x="102" y="159" width="125" color="0x766b62" font="SimSun" var="textinput1" editable="true" align="center"/>
			  <Image url="jpg.common.cs2_bg3" x="110" y="52"/>
			  <Image url="png.common.cs2_jinbi" x="103" y="193" var="goldImg"/>
			</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        public function log(param1:String, param2:int = 0) : void
        {
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        public function init() : void
        {
            this.background = new Sprite();
            this.background.graphics.beginFill(0, 0.5);
            this.background.graphics.drawRect(0, 0, GlobalLayer.instance.root.stage.stageWidth, GlobalLayer.instance.root.stage.stageHeight);
            this.background.graphics.endFill();
            this.background.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            PluginManager.instance.alertContainer.addChild(this.background);
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.sureBtn.addEventListener(MouseEvent.CLICK, this.onSure);
            this.cancelBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            this.addEventListener(MouseEvent.CLICK, this.onStageClicked);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onStageClicked(event:MouseEvent) : void
        {
            GlobalLayer.instance.flashStage.focus = null;
            this.curCount = int(this.textinput1.text);
            this.changeNumText(this.curCount);
            return;
        }// end function

        private function changeNumText(param1:int) : void
        {
            return;
        }// end function

        private function onSure(event:MouseEvent) : void
        {
            var _loc_2:* = int(this.textinput1.text);
            PluginManager.instance.sendToServer("stallage", CMDStallage.BuyItem, {itemid:this.data[0], type:this.data[5], value:this.data[6], count:_loc_2, index:this.index, rid:this.rid});
            this.close();
            if (this.curCount == 0)
            {
                return;
            }
            return;
        }// end function

        public function show(param1:Object) : void
        {
            this.data = param1[0];
            this.index = param1[1];
            this.rid = param1[2];
            this.darwItem();
            this.item_name.text = this.data[4].name;
            if (this.data[5] == 6)
            {
                this.goldImg.visible = true;
                this.yuanbaoImg.visible = false;
            }
            else
            {
                this.goldImg.visible = false;
                this.yuanbaoImg.visible = true;
            }
            var _loc_2:* = UserData.getUserData("gold");
            var _loc_3:* = this.data[1];
            var _loc_4:int = 1;
            this.maxCount = _loc_3;
            this.textinput1.text = String(this.data[7]);
            var _loc_5:* = int(this.data[6]) * int(this.textinput1.text);
            this.textinput2.text = String(_loc_5);
            this.price = _loc_5;
            var _loc_6:Boolean = true;
            this.visible = true;
            this.background.visible = _loc_6;
            return;
        }// end function

        private function darwItem() : void
        {
            if (this.item)
            {
                this.item.parent.removeChild(this.item);
            }
            var imgURL:* = new URLRequest();
            imgURL.url = Config.getUrl("assets/images/icon/tools/" + this.data[4].icon + ".png", ResourceType.NORMAL);
            this.item = new Loader();
            this.item.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function () : void
            {
                return;
            }// end function
            );
            this.item.load(imgURL);
            this.item.x = 93 + 22;
            this.item.y = 23 + 35;
            this.addChild(this.item);
            this.item_name.text = this.data[4].name;
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            this.curCount = 1;
            this.textinput1.text = this.curCount.toString();
            this.textinput2.text = (int(this.data[6]) * int(this.textinput1.text)).toString();
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            this.data = null;
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.background.width = GlobalLayer.instance.root.stage.stageWidth;
            this.background.height = GlobalLayer.instance.root.stage.stageHeight;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
